/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:56 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{
    public class SukienslideDAL : SqlProvider<SukienslideEntity>
    {
        static SukienslideDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                SukienslideEntity entity = new SukienslideEntity();
                entity.PK_iSukienslideID = Int64.Parse("0" + dr["PK_iSukienslideID"].ToString());
                entity.FK_iTrangslideID = Int64.Parse("0" + dr["FK_iTrangslideID"].ToString());
                entity.iSothutu = short.Parse("0" + dr["iSothutu"].ToString());
                entity.bBatdaucungsukientruoc = Boolean.Parse(dr["bBatdaucungsukientruoc"].ToString());
                entity.sNoidung = dr["sNoidung"].ToString();
                entity.iThoigianhienthi = short.Parse("0" + dr["iThoigianhienthi"].ToString());
                entity.FK_sDanhmucsukienbatdauID = dr["FK_sDanhmucsukienslideBatdauID"].ToString();
                entity.FK_sDanhmucsukienkethucID = dr["FK_sDanhmucsukienslideKetthucID"].ToString();
                return entity;
            };
        }
        public static SukienslideEntity GetOne(Int64 PK_iSukienslideID)
        {
            string cmdName = "spSukienslide_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iSukienslideID", PK_iSukienslideID);
            SukienslideEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<SukienslideEntity> GetAll()
        {
            string cmdName = "spSukienslide_Get";
            return GetList(cmdName);
        }

        public static List<SukienslideEntity> GetByFK_iTrangslideID(Int64 FK_iTrangslideID)
        {
            string cmdName = "spSukienslide_GetByFK_iTrangslideID";
            SqlParameter p = new SqlParameter("@FK_iTrangslideID", FK_iTrangslideID);
            List<SukienslideEntity> lst = GetList(cmdName, p);
            return lst;
        }
        
        public static int Add(SukienslideEntity entity)
        {
            string cmdName = "spSukienslide_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(SukienslideEntity entity)
        {
            string cmdName = "spSukienslide_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 PK_iSukienslideID)
        {
            string cmdName = "spSukienslide_Delete";
            SqlParameter p = new SqlParameter("@PK_iSukienslideID", PK_iSukienslideID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(SukienslideEntity entity)
        {
            SqlParameter[] p = new SqlParameter[8];
			p[0] = new SqlParameter("@PK_iSukienslideID", entity.PK_iSukienslideID);
            p[1] = new SqlParameter("@FK_iTrangslideID", entity.FK_iTrangslideID);
            p[2] = new SqlParameter("@iSothutu", entity.iSothutu);
			p[3] = new SqlParameter("@sNoidung", entity.sNoidung);
			p[4] = new SqlParameter("@iThoigianhienthi", entity.iThoigianhienthi);
            p[5] = new SqlParameter("@FK_sDanhmucsukienslideBatdauID", entity.FK_sDanhmucsukienbatdauID);
            p[6] = new SqlParameter("@FK_sDanhmucsukienslideKetthucID", entity.FK_sDanhmucsukienkethucID);
            p[7] = new SqlParameter("@bBatdaucungsukientruoc", entity.bBatdaucungsukientruoc);
            return p;
        }
        #endregion
       
    }
}